package com.linktrip.devicemanager.async;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSONObject;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.linktrip.devicemanager.sms.SMSConfig;
import com.linktrip.devicemanager.util.HttpUtil;
import com.linktrip.devicemanager.entity.DeviceLog;
import com.linktrip.devicemanager.entity.DeviceInfo;
import org.springframework.scheduling.annotation.Async;
import com.linktrip.devicemanager.server.DeviceLogService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author : CaineZhu E-mail:CaineZhu@me.com
 * @version : V1.0
 * @创建时间 ： 2017年5月17日 上午10:32:06
 * @类说明 : 异步任务线程
 */

@Component(value = "callbackTaskService")
public class CallbackTaskService {

	Logger logger = LoggerFactory.getLogger(CallbackTaskService.class);

//	@Autowired
//	DeviceLogService deviceLogService;
//
//	@Async("saveLogAsync")
//	public void saveLog(DeviceLog log) {
//		deviceLogService.addDeviceLog(log);// 存入数据库
//	}

	@Async("callbackAsync")
	public void dataCallback(DeviceInfo info) {
		JSONObject obj = (JSONObject) JSONObject.toJSON(info);
		if (!SMSConfig.getTestDevicesList().equals("")&&SMSConfig.getTestDevicesList().contains(info.getDevice_no())) {
			HttpUtil.callbackData(SMSConfig.getTestCallBackUrl(), "POST", obj.toJSONString(), null);
		} else {
			HttpUtil.callbackData(SMSConfig.getCallBackUrl(), "POST", obj.toJSONString(), null);
		}
	}
	
}
